<?php
/**
 * 人脸登陆唯一凭证
 * Created by PhpStorm.
 * User: liyy
 * Date: 2017/7/27 0027
 * Time: 下午 3:39
 */

namespace app\api\model;

use think\Db;
use think\Model;
class FaceOpenid extends Model{

    /**
     * [insert 人脸新增]
     * @param  [string] $openid [人脸图片唯一]
     * @param  [string] $userid [用户id]
     * @return [int]    $return [返回]
     */
    public function insert($openid,$userid,$group){
        if (empty($openid) || empty($userid) || empty($openid)) {
           return false;
        }   
        $data['open_id'] = $openid;
        $data['uid'] = $userid;
        $data['createtime'] = time();
        $data['updatetime'] = time();
        $data['group'] = $group;
        $result = Db::name('face_openid')->insert($data);
        return $result;
    }

    /**
     * [selectopenid 查询是否存在该图片]
     */
    public function selectopenid($openid,$uid){
        $data['open_id'] = $openid;
        $data['uid'] = $uid;
        $return = Db::name('face_openid')->where($data)->find();
        return $return;
    }

    /**
     * [face_log 查询人脸日志表]
     * @param  [array] $data   [数据]
     * @param  [int]   $status [0-失败 1-成功]
     * @return [booler]        
     */
    public function face_log($result,$status=0){
        if(empty($result['open_id']) || empty($result['face_log']) || empty($result['userid'])){
            return false;
        }
        $data['open_id']  = $result['open_id'];
        $data['face_log'] = $result['face_log'];
        $data['uid'] = $result['userid'];
        $data['status'] = $status;
        $data['createtime'] = time();
        $return = Db::name('face_log')->insert($data);
        return $return;
    }


}